package com.harvest.scientific.ladder.page.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.harvest.scientific.ladder.adpater.BaseMultiItemAdapter
import com.harvest.scientific.ladder.databinding.MultiNoOrderItemLayoutBinding
import com.harvest.scientific.ladder.databinding.MultiOrderItemLayoutBinding
import com.harvest.scientific.ladder.page.ui.main.InjurePacificChickenRes

/**
 * @author：zenglingwen
 * @date：2024-06-10 23:09
 * @desc：
 */

class MultiStatusListAdapter() :
    BaseMultiItemAdapter<InjurePacificChickenRes>(arrayListOf()) {

    class MultiNoOrderHolder(val viewBinding: MultiNoOrderItemLayoutBinding) :
        RecyclerView.ViewHolder(viewBinding.root)

    class MultiOrderHolder(val viewBinding: MultiOrderItemLayoutBinding) :
        RecyclerView.ViewHolder(viewBinding.root)


    // 在 init 初始化的时候，添加多类型
    init {
        addItemType(
            MULTI_STATUS_NO_ORDER,
            object :
                OnMultiItemAdapterListener<InjurePacificChickenRes, MultiNoOrderHolder> { // 类型 1
                override fun onCreate(
                    context: Context,
                    parent: ViewGroup,
                    viewType: Int
                ): MultiNoOrderHolder {
                    // 创建 viewholder
                    val viewBinding =
                        MultiNoOrderItemLayoutBinding.inflate(LayoutInflater.from(context), parent, false)
                    return MultiNoOrderHolder(viewBinding)
                }

                override fun onBind(
                    holder: MultiNoOrderHolder,
                    position: Int,
                    item: InjurePacificChickenRes?
                ) {
                    // 绑定 item 数据
                }
            }).addItemType(
            MULTI_STATUS_ORDERED,
            object : OnMultiItemAdapterListener<InjurePacificChickenRes, MultiOrderHolder> { // 类型 2
                override fun onCreate(
                    context: Context,
                    parent: ViewGroup,
                    viewType: Int
                ): MultiOrderHolder {
                    // 创建 viewholder
                    val viewBinding =
                        MultiOrderItemLayoutBinding.inflate(LayoutInflater.from(context), parent, false)
                    return MultiOrderHolder(viewBinding)
                }

                override fun onBind(
                    holder: MultiOrderHolder,
                    position: Int,
                    item: InjurePacificChickenRes?
                ) {
                    // 绑定 item 数据
                }


            }).onItemViewType { position, list -> // 根据数据，返回对应的 ItemViewType
            if (list[position].mostEndlessComfortableLightning == "0") {
                MULTI_STATUS_NO_ORDER
            } else {
                MULTI_STATUS_ORDERED
            }
        }
    }

    companion object {
        private const val MULTI_STATUS_NO_ORDER = 0
        private const val MULTI_STATUS_ORDERED = 1

    }
}